package com.pw.study.realtime.bean

import java.text.SimpleDateFormat

case class SaleDetail(
                       var order_detail_id: String = null,
                       var order_id: String = null,
                       var order_status: String = null,
                       var create_time: String = null,
                       var user_id: String = null,
                       var sku_id: String = null,
                       var user_gender: String = null,
                       var user_age: Int = 0,
                       var user_level: String = null,
                       var sku_price: Double = 0D,
                       var sku_name: String = null,
                       var dt: String = null) {
  def this(OrderBean: OrderBean, orderDetail: OrderDetail) {
    this
    mergeOrderBean(OrderBean)
    mergeOrderDetail(orderDetail)
  }

  def mergeOrderBean(OrderBean: OrderBean): Unit = {
    if (OrderBean != null) {
      this.order_id = OrderBean.id
      this.order_status = OrderBean.order_status
      this.create_time = OrderBean.create_time
      this.dt = OrderBean.create_date
      this.user_id = OrderBean.user_id
    }
  }

  def mergeOrderDetail(orderDetail: OrderDetail): Unit = {
    if (orderDetail != null) {
      this.order_detail_id = orderDetail.id
      this.sku_id = orderDetail.sku_id
      this.sku_name = orderDetail.sku_name
      this.sku_price = orderDetail.order_price.toDouble
    }
  }

  def mergeUserInfo(userInfo: UserInfo): Unit = {
    if (userInfo != null) {
      this.user_id = userInfo.id

      val formattor = new SimpleDateFormat("yyyy-MM-dd")
      val date: java.util.Date = formattor.parse(userInfo.birthday)
      val curTs: Long = System.currentTimeMillis()
      val betweenMs = curTs - date.getTime
      val age = betweenMs / 1000L / 60L / 60L / 24L / 365L

      this.user_age = age.toInt
      this.user_gender = userInfo.gender
      this.user_level = userInfo.user_level
    }
  }
}
